#include <Ogre.h>
#include <OIS/OIS.h>
using namespace Ogre;

#include "MarbleMax.h"

void Marble_Max::moveCamera()
{
	Ogre::Real pitchAngle;					// angle for looking up and down
	Ogre::Real pitchAngleSign;				// negative or positive

	camYawNode->yaw(mRotX);					// turn left or right
	camPitchNode->pitch(mRotY);				// look up or down
	camNode->translate(camYawNode->getOrientation() * camPitchNode->getOrientation() * mTranslateVector, SceneNode::TS_LOCAL);	// move in faced direction

	pitchAngle = (2 * Ogre::Degree(Ogre::Math::ACos(camPitchNode->getOrientation().w)).valueDegrees());		// get the up or down angle
	pitchAngleSign = camPitchNode->getOrientation().x;	// see if positive or negative
	
	if(pitchAngle > 90.0f)					// lock camera to look straight down or straight up and no more, so cannot go upside down
	{
		if(pitchAngleSign > 0)
			camPitchNode->setOrientation(Ogre::Quaternion(Ogre::Math::Sqrt(0.5f),Ogre::Math::Sqrt(0.5f), 0, 0));
		else if(pitchAngleSign < 0)
			camPitchNode->setOrientation(Ogre::Quaternion(Ogre::Math::Sqrt(0.5f),-Ogre::Math::Sqrt(0.5f), 0, 0));
	}
}